package com.kk.hystrix.demo.command;

import com.kk.hystrix.demo.service.HelloWorldService;
import com.kk.hystrix.demo.service.impl.HelloWorldServiceImpl;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;

/**
* HelloWorldCommand.java
* 类说明 TODO
*
* @author chengkai
* @date  2017年6月19日 下午6:20:37
*/
public class HelloWorldCommand extends HystrixCommand<String> {

    private HelloWorldService helloWorldService;

    private String name;

    public HelloWorldCommand(String name) {
        super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"));
        this.helloWorldService = new HelloWorldServiceImpl();
        this.name = name;
    }

    @Override
    protected String run() throws Exception {
        System.out.println(name);
        return helloWorldService.hello(name);
    }

    /**
     * 熔断逻辑,非HystrixBadRequestException异常会走此方法
     */
    @Override
    protected String getFallback() {
        return "Hello fail " + name;
    }

}
